package com.jic.market.common.util;

import lombok.extern.slf4j.Slf4j;

import java.net.InetAddress;

/**
 * @author guohuayong
 * @date: 2020年01月10日
 */
@Slf4j
public class IpUtil {

	private static final String X_FORWARDED_FOR = "x-forwarded-for";
	private static final String PROXY_CLIENT_IP = "Proxy-Client-IP";
	private static final String WL_PROXY_CLIENT_IP = "WL-Proxy-Client-IP";

	private static final String LOCALHOST_IP = "127.0.0.1";
	private static final String LOCALHOST_IP_16 = "0:0:0:0:0:0:0:1";
	private static final String UNKNOWN = "unknown";
	private static final String COMMA = ",";
	private static final int MAX_IP_LENGTH = 15;


	public static final String getLocalAddress() {
		String ip = "";
		try {
			InetAddress addr = InetAddress.getLocalHost();
			// 获取本机ip
			ip = addr.getHostAddress().toString();
		} catch (Exception e) {
			ip = "127.0.0.1";
		}
		return ip;
	}

	public static final String getLocalHostName() {
		String hostName = "";
		try {
			InetAddress addr = InetAddress.getLocalHost();
			// 获取本机ip
			hostName = addr.getHostName();
		} catch (Exception e) {
			hostName = "localhost";
		}
		return hostName;
	}

}
